load("//bazel:mongo_src_rules.bzl", "idl_generator", "mongo_cc_library", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

idl_generator(
    name = "sharding_api_d_params_gen",
    src = "sharding_api_d_params.idl",
)

idl_generator(
    name = "type_shard_identity_gen",
    src = "type_shard_identity.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "shard_authoritative_catalog_gen",
    src = "shard_authoritative_catalog.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "collection_critical_section_document_gen",
    src = "collection_critical_section_document.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "commit_chunk_migration_gen",
    src = "commit_chunk_migration.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/idl:generic_argument_gen",
        "//src/mongo/s:chunk_version_gen",
        "//src/mongo/s:sharding_types_gen",
    ],
)

idl_generator(
    name = "document_source_analyze_shard_key_read_write_distribution_gen",
    src = "document_source_analyze_shard_key_read_write_distribution.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/s:analyze_shard_key_cmd_gen",
        "//src/mongo/s:sharding_types_gen",
    ],
)

idl_generator(
    name = "migration_coordinator_document_gen",
    src = "migration_coordinator_document.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db/session:logical_session_id_gen",
        "//src/mongo/s:chunk_range_gen",
        "//src/mongo/s:chunk_version_gen",
        "//src/mongo/s:sharding_types_gen",
    ],
)

idl_generator(
    name = "migration_recipient_recovery_document_gen",
    src = "migration_recipient_recovery_document.idl",
    deps = [
        ":migration_coordinator_document_gen",
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "range_deletion_task_gen",
    src = "range_deletion_task.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db:keypattern_gen",
        "//src/mongo/db/session:logical_session_id_gen",
        "//src/mongo/s:chunk_range_gen",
        "//src/mongo/s:sharding_types_gen",
    ],
)

idl_generator(
    name = "sharding_runtime_d_params_gen",
    src = "sharding_runtime_d_params.idl",
)

mongo_cc_library(
    name = "balancer_stats_registry",
    srcs = [
        "balancer_stats_registry.cpp",
    ],
    hdrs = [
        "balancer_stats_registry.h",
        "range_deleter_service.h",
        "sharding_runtime_d_params.h",
        ":range_deletion_task_gen",
        ":sharding_runtime_d_params_gen",
    ],
    deps = [
        "//src/mongo/db:dbdirectclient",
        "//src/mongo/db:shard_role",
        "//src/mongo/db/repl:replica_set_aware_service",
        "//src/mongo/s:grid",
        "//src/mongo/util/concurrency:spin_lock",
    ],
)

idl_generator(
    name = "type_shard_collection_gen",
    src = "type_shard_collection.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db:keypattern_gen",
        "//src/mongo/s:chunk_version_gen",
        "//src/mongo/s:type_collection_common_types_gen",
        "//src/mongo/s/resharding:type_collection_fields_gen",
    ],
)

idl_generator(
    name = "type_shard_database_gen",
    src = "type_shard_database.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/s:sharding_types_gen",
    ],
)

idl_generator(
    name = "user_writes_critical_section_document_gen",
    src = "user_writes_critical_section_document.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "transaction_coordinator_document_gen",
    src = "transaction_coordinator_document.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db/session:logical_session_id_gen",
        "//src/mongo/s:sharding_types_gen",
    ],
)

idl_generator(
    name = "transaction_coordinator_params_gen",
    src = "transaction_coordinator_params.idl",
)

idl_generator(
    name = "transaction_coordinators_stats_gen",
    src = "transaction_coordinators_stats.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "forwardable_operation_metadata_gen",
    src = "forwardable_operation_metadata.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/rpc/metadata:impersonated_user_metadata_gen",
    ],
)

mongo_cc_library(
    name = "forwardable_operation_metadata",
    srcs = [
        "forwardable_operation_metadata.cpp",
        "forwardable_operation_metadata_gen",
    ],
    hdrs = [
        "forwardable_operation_metadata.h",
    ],
    deps = [
        "//src/mongo/db:server_base",
        "//src/mongo/db:write_block_bypass",
        "//src/mongo/db/auth",
        "//src/mongo/db/auth:security_token",
        "//src/mongo/db/auth:security_token_auth",
        "//src/mongo/rpc:metadata_impersonated_user",
        "//src/mongo/util/concurrency:spin_lock",  # TODO(SERVER-93876): Remove.
    ],
)

idl_generator(
    name = "add_shard_cmd_gen",
    src = "add_shard_cmd.idl",
    deps = [
        ":type_shard_identity_gen",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/idl:generic_argument_gen",
    ],
)

idl_generator(
    name = "participant_block_gen",
    src = "participant_block.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/idl:generic_argument_gen",
    ],
)

idl_generator(
    name = "remove_tags_gen",
    src = "remove_tags.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/idl:generic_argument_gen",
    ],
)

idl_generator(
    name = "sharded_index_catalog_commands_gen",
    src = "sharded_index_catalog_commands.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/s:index_version_gen",
        "//src/mongo/s:sharding_types_gen",
        "//src/mongo/s/catalog:type_index_catalog_gen",
    ],
)

idl_generator(
    name = "sharding_config_server_parameters_gen",
    src = "sharding_config_server_parameters.idl",
)

idl_generator(
    name = "cleanup_structured_encryption_data_coordinator_gen",
    src = "cleanup_structured_encryption_data_coordinator.idl",
    deps = [
        ":sharding_ddl_coordinator_gen",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db/commands:fle2_cleanup_gen",
    ],
)

idl_generator(
    name = "collmod_coordinator_document_gen",
    src = "collmod_coordinator_document.idl",
    deps = [
        ":sharding_ddl_coordinator_gen",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db:coll_mod_gen",
        "//src/mongo/s:sharding_types_gen",
    ],
)

idl_generator(
    name = "compact_structured_encryption_data_coordinator_gen",
    src = "compact_structured_encryption_data_coordinator.idl",
    deps = [
        ":sharding_ddl_coordinator_gen",
        "//src/mongo/crypto:fle_field_schema_gen",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db/commands:fle2_compact_gen",
    ],
)

idl_generator(
    name = "convert_to_capped_coordinator_document_gen",
    src = "convert_to_capped_coordinator_document.idl",
    deps = [
        ":sharding_ddl_coordinator_gen",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/s/request_types:sharded_ddl_commands_gen",
    ],
)

idl_generator(
    name = "create_collection_coordinator_document_gen",
    src = "create_collection_coordinator_document.idl",
    deps = [
        ":sharding_ddl_coordinator_gen",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/s/request_types:sharded_ddl_commands_gen",
    ],
)

idl_generator(
    name = "create_database_coordinator_document_gen",
    src = "create_database_coordinator_document.idl",
    deps = [
        ":sharding_ddl_coordinator_gen",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/s:sharding_types_gen",
    ],
)

idl_generator(
    name = "drop_collection_coordinator_document_gen",
    src = "drop_collection_coordinator_document.idl",
    deps = [
        ":sharding_ddl_coordinator_gen",
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "drop_database_coordinator_document_gen",
    src = "drop_database_coordinator_document.idl",
    deps = [
        ":sharding_ddl_coordinator_gen",
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "move_primary_coordinator_document_gen",
    src = "move_primary_coordinator_document.idl",
    deps = [
        ":sharding_ddl_coordinator_gen",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/s:sharding_types_gen",
    ],
)

idl_generator(
    name = "refine_collection_shard_key_coordinator_document_gen",
    src = "refine_collection_shard_key_coordinator_document.idl",
    deps = [
        ":sharding_ddl_coordinator_gen",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/s/request_types:sharded_ddl_commands_gen",
    ],
)

idl_generator(
    name = "remove_chunks_gen",
    src = "remove_chunks.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/idl:generic_argument_gen",
    ],
)

idl_generator(
    name = "remove_shard_commit_coordinator_document_gen",
    src = "remove_shard_commit_coordinator_document.idl",
    deps = [
        ":sharding_ddl_coordinator_gen",
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "reshard_collection_coordinator_document_gen",
    src = "reshard_collection_coordinator_document.idl",
    deps = [
        ":sharding_ddl_coordinator_gen",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/s/request_types:sharded_ddl_commands_gen",
    ],
)

idl_generator(
    name = "resharding_test_commands_gen",
    src = "resharding_test_commands.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/idl:generic_argument_gen",
        "//src/mongo/s:sharding_types_gen",
    ],
)

idl_generator(
    name = "set_allow_migrations_coordinator_document_gen",
    src = "set_allow_migrations_coordinator_document.idl",
    deps = [
        ":sharding_ddl_coordinator_gen",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/s/request_types:sharded_ddl_commands_gen",
    ],
)

idl_generator(
    name = "sharded_collmod_gen",
    src = "sharded_collmod.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db:coll_mod_gen",
    ],
)

idl_generator(
    name = "sharded_rename_collection_gen",
    src = "sharded_rename_collection.idl",
    deps = [
        ":sharding_ddl_coordinator_gen",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/s/request_types:sharded_ddl_commands_gen",
    ],
)

idl_generator(
    name = "sharding_ddl_coordinator_gen",
    src = "sharding_ddl_coordinator.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db/session:logical_session_id_gen",
        "//src/mongo/s:database_version_gen",
        "//src/mongo/s:error_status_gen",
    ],
)

idl_generator(
    name = "transition_to_sharded_cluster_gen",
    src = "transition_to_sharded_cluster.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/idl:generic_argument_gen",
    ],
)

idl_generator(
    name = "untrack_unsplittable_collection_coordinator_document_gen",
    src = "untrack_unsplittable_collection_coordinator_document.idl",
    deps = [
        ":sharding_ddl_coordinator_gen",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/s/request_types:sharded_ddl_commands_gen",
    ],
)

mongo_cc_library(
    name = "resharding_server_parameters_idl",
    srcs = ["//src/mongo/db/s/resharding:resharding_server_parameters_gen"],
    deps = ["//src/mongo/db:server_base"],
)

mongo_cc_library(
    name = "analyze_shard_key_util",
    srcs = [
        "analyze_shard_key_util.cpp",
    ],
    hdrs = [
        "analyze_shard_key_util.h",
    ],
    deps = [
        "//src/mongo/db:shard_role",
        "//src/mongo/s:analyze_shard_key_common",
    ],
)

mongo_cc_library(
    name = "user_writes_recoverable_critical_section",
    srcs = [
        "user_writes_recoverable_critical_section_service.cpp",
        ":user_writes_critical_section_document_gen",
    ],
    hdrs = [
        "user_writes_recoverable_critical_section_service.h",
        "//src/mongo/db:persistent_task_store.h",
    ],
    deps = [
        "//src/mongo/db:dbdirectclient",
        "//src/mongo/db:rw_concern_d",
        "//src/mongo/db:shard_role_api",
        "//src/mongo/db/repl:replica_set_aware_service",
    ],
)

mongo_cc_library(
    name = "sharding_logging",
    srcs = [
        "sharding_logging.cpp",
    ],
    hdrs = [
        "sharding_logging.h",
    ],
    deps = [
        "//src/mongo/db:shard_role_api",
        "//src/mongo/s/catalog:sharding_catalog_client_impl",
    ],
)

mongo_cc_library(
    name = "query_analysis_writer",
    srcs = [
        "query_analysis_writer.cpp",
    ],
    hdrs = [
        "query_analysis_writer.h",
    ],
    deps = [
        ":analyze_shard_key_util",
        "//src/mongo/db:dbdirectclient",
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context",
        "//src/mongo/db:shard_role",
        "//src/mongo/db/query/write_ops:write_ops_parsers",
        "//src/mongo/db/repl:replica_set_aware_service",
        "//src/mongo/s:analyze_shard_key_common",
        "//src/mongo/s:query_analysis_sampler",
    ],
)

mongo_cc_library(
    name = "sharding_catalog",
    srcs = [
        "sharding_index_catalog_ddl_util.cpp",
        ":shard_authoritative_catalog_gen",
    ],
    hdrs = [
        "sharding_index_catalog_ddl_util.h",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:dbhelpers",
        "//src/mongo/db:shard_role",
        "//src/mongo/db/collection_crud",
        "//src/mongo/db/concurrency:exception_util",
        "//src/mongo/db/query/query_stats",
        "//src/mongo/db/query/write_ops",
        "//src/mongo/s:common_s",
    ],
)

mongo_cc_library(
    name = "transaction_coordinator",
    srcs = [
        "server_transaction_coordinators_metrics.cpp",
        "single_transaction_coordinator_stats.cpp",
        "transaction_coordinator.cpp",
        "transaction_coordinator_catalog.cpp",
        "transaction_coordinator_curop.cpp",
        "transaction_coordinator_futures_util.cpp",
        "transaction_coordinator_metrics_observer.cpp",
        "transaction_coordinator_service.cpp",
        "transaction_coordinator_structures.cpp",
        "transaction_coordinator_util.cpp",
        "transaction_coordinator_worker_curop_repository_mongod.cpp",
        ":transaction_coordinator_document_gen",
        ":transaction_coordinator_params_gen",
        ":transaction_coordinators_stats_gen",
    ],
    hdrs = [
        "server_transaction_coordinators_metrics.h",
        "single_transaction_coordinator_stats.h",
        "transaction_coordinator.h",
        "transaction_coordinator_catalog.h",
        "transaction_coordinator_curop.h",
        "transaction_coordinator_futures_util.h",
        "transaction_coordinator_metrics_observer.h",
        "transaction_coordinator_service.h",
        "transaction_coordinator_structures.h",
        "transaction_coordinator_util.h",
    ],
    header_deps = [
        "//src/mongo/db/pipeline/process_interface:mongos_process_interface",
    ],
    tags = ["compile_requires_large_memory_gcc"],
    deps = [
        "//src/mongo/db:dbdirectclient",
        "//src/mongo/db:internal_transactions_feature_flag",
        "//src/mongo/db:not_primary_error_tracker",
        "//src/mongo/db:rw_concern_d",
        "//src/mongo/db:server_feature_flags",
        "//src/mongo/db:shard_role_api",
        "//src/mongo/db:vector_clock_mongod",
        "//src/mongo/db/commands:server_status_core",
        "//src/mongo/db/commands:txn_cmd_request",
        "//src/mongo/db/repl:change_stream_oplog_notification",
        "//src/mongo/db/repl:wait_for_majority_service",
        "//src/mongo/db/transaction",
        "//src/mongo/executor:task_executor_pool",
        "//src/mongo/s:grid",
    ],
)

mongo_cc_library(
    name = "sharding_catalog_manager",
    srcs = [
        "add_shard_util.cpp",
        "create_database_util.cpp",
        "ddl_lock_manager.cpp",
        "periodic_sharded_index_consistency_checker.cpp",
        "sharding_ddl_util.cpp",
        "sharding_index_catalog_util.cpp",
        "sharding_util.cpp",
        "split_chunk_request_type.cpp",
        "type_shard_identity.cpp",
        ":add_shard_cmd_gen",
        ":participant_block_gen",
        ":remove_tags_gen",
        ":sharded_index_catalog_commands_gen",
        ":sharding_config_server_parameters_gen",
        ":type_shard_identity_gen",
        "//src/mongo/db/s/balancer:auto_merger_policy.cpp",
        "//src/mongo/db/s/balancer:balance_stats.cpp",
        "//src/mongo/db/s/balancer:balancer.cpp",
        "//src/mongo/db/s/balancer:balancer_chunk_selection_policy.cpp",
        "//src/mongo/db/s/balancer:balancer_commands_scheduler_impl.cpp",
        "//src/mongo/db/s/balancer:balancer_defragmentation_policy.cpp",
        "//src/mongo/db/s/balancer:balancer_policy.cpp",
        "//src/mongo/db/s/balancer:cluster_statistics.cpp",
        "//src/mongo/db/s/balancer:cluster_statistics_impl.cpp",
        "//src/mongo/db/s/balancer:move_unsharded_policy.cpp",
        "//src/mongo/db/s/config:index_on_config.cpp",
        "//src/mongo/db/s/config:initial_split_policy.cpp",
        "//src/mongo/db/s/config:placement_history_cleaner.cpp",
        "//src/mongo/db/s/config:sharding_catalog_manager.cpp",
        "//src/mongo/db/s/config:sharding_catalog_manager_chunk_operations.cpp",
        "//src/mongo/db/s/config:sharding_catalog_manager_collection_operations.cpp",
        "//src/mongo/db/s/config:sharding_catalog_manager_database_operations.cpp",
        "//src/mongo/db/s/config:sharding_catalog_manager_shard_operations.cpp",
        "//src/mongo/db/s/config:sharding_catalog_manager_zone_operations.cpp",
    ],
    hdrs = [
        "add_shard_util.h",
        "create_database_util.h",
        "ddl_lock_manager.h",
        "periodic_sharded_index_consistency_checker.h",
        "sharding_ddl_util.h",
        "sharding_index_catalog_util.h",
        "sharding_util.h",
        "split_chunk_request_type.h",
        "type_shard_identity.h",
        "//src/mongo/bson:bsonobj_comparator.h",
        "//src/mongo/db/s/balancer:actions_stream_policy.h",
        "//src/mongo/db/s/balancer:auto_merger_policy.h",
        "//src/mongo/db/s/balancer:balance_stats.h",
        "//src/mongo/db/s/balancer:balancer.h",
        "//src/mongo/db/s/balancer:balancer_chunk_selection_policy.h",
        "//src/mongo/db/s/balancer:balancer_commands_scheduler.h",
        "//src/mongo/db/s/balancer:balancer_commands_scheduler_impl.h",
        "//src/mongo/db/s/balancer:balancer_defragmentation_policy.h",
        "//src/mongo/db/s/balancer:balancer_policy.h",
        "//src/mongo/db/s/balancer:cluster_statistics.h",
        "//src/mongo/db/s/balancer:cluster_statistics_impl.h",
        "//src/mongo/db/s/balancer:move_unsharded_policy.h",
        "//src/mongo/db/s/config:index_on_config.h",
        "//src/mongo/db/s/config:initial_split_policy.h",
        "//src/mongo/db/s/config:placement_history_cleaner.h",
        "//src/mongo/db/s/config:sharding_catalog_manager.h",
        "//src/mongo/s:chunk_constraints.h",
    ],
    # TODO(SERVER-97809)
    # sharding_ddl_util.cpp needs more than 3.5GB of ram for gcc+fission builds
    exec_properties = select({
        "//bazel/config:linux_gcc_fission_x86_64": {
            "Pool": "large_memory_x86_64",
        },
        "//bazel/config:linux_gcc_fission_aarch64": {
            "Pool": "large_memory_arm64",
        },
        "//conditions:default": {},
    }),
    deps = [
        ":forwardable_operation_metadata",
        ":resharding_server_parameters_idl",
        ":sharding_logging",
        ":user_writes_recoverable_critical_section",
        "//src/mongo:base",
        "//src/mongo/bson/util:bson_extract",
        "//src/mongo/client:fetcher",
        "//src/mongo/db:audit",
        "//src/mongo/db:cluster_transaction_api",
        "//src/mongo/db:coll_mod_command_idl",
        "//src/mongo/db:common",
        "//src/mongo/db:dbdirectclient",
        "//src/mongo/db:index_commands_idl",
        "//src/mongo/db:internal_transactions_feature_flag",
        "//src/mongo/db:keys_collection_util",
        "//src/mongo/db:rw_concern_d",
        "//src/mongo/db:server_feature_flags",
        "//src/mongo/db:shard_role",
        "//src/mongo/db:snapshot_window_options",
        "//src/mongo/db:vector_clock_mongod",
        "//src/mongo/db/auth:security_token_auth",
        "//src/mongo/db/catalog:catalog_helpers",
        "//src/mongo/db/catalog:collection_options",
        "//src/mongo/db/commands:cluster_server_parameter_commands_invocation",
        "//src/mongo/db/commands:list_databases_command",
        "//src/mongo/db/commands:mongod_fcv",
        "//src/mongo/db/commands:notify_sharding_event_idl",
        "//src/mongo/db/commands:set_feature_compatibility_version_idl",
        "//src/mongo/db/commands:set_user_write_block_mode_idl",
        "//src/mongo/db/concurrency:exception_util",
        "//src/mongo/db/index_builds:index_builds_coordinator",
        "//src/mongo/db/pipeline:sharded_agg_helpers",
        "//src/mongo/db/pipeline/process_interface:shardsvr_process_interface",
        "//src/mongo/db/repl:hello_command",
        "//src/mongo/db/repl:read_concern_args",
        "//src/mongo/db/repl:repl_coordinator_interface",
        "//src/mongo/db/repl:replica_set_aware_service",
        "//src/mongo/db/timeseries:timeseries_options",
        "//src/mongo/db/transaction",
        "//src/mongo/db/transaction:transaction_api",
        "//src/mongo/executor:async_rpc",
        "//src/mongo/executor:inline_executor",
        "//src/mongo/executor:network_interface",
        "//src/mongo/idl:cluster_server_parameter_common",
        "//src/mongo/s:common_s",
        "//src/mongo/s/catalog:sharding_catalog_client_impl",
        "//src/mongo/s/client:sharding_client",
        "//src/mongo/s/query/planner:cluster_aggregate",
        "//src/mongo/util:log_and_backoff",
        "//src/mongo/util:pcre_wrapper",
    ],
)

mongo_cc_library(
    name = "sessions_collection_config_server",
    srcs = [
        "sessions_collection_config_server.cpp",
    ],
    hdrs = [
        "sessions_collection_config_server.h",
    ],
    deps = [
        ":sharding_catalog_manager",
        "//src/mongo/db:dbdirectclient",
        "//src/mongo/db/pipeline:sharded_agg_helpers",
        "//src/mongo/s:sessions_collection_sharded",
        "//src/mongo/s:sharding_api",
    ],
)

mongo_cc_library(
    name = "sharding_runtime_d",
    srcs = [
        "active_migrations_registry.cpp",
        "analyze_shard_key_read_write_distribution.cpp",
        "auto_split_vector.cpp",
        "chunk_move_write_concern_options.cpp",
        "chunk_operation_precondition_checks.cpp",
        "collection_sharding_runtime.cpp",
        "collection_sharding_state_factory_shard.cpp",
        "config_server_op_observer.cpp",
        "document_source_analyze_shard_key_read_write_distribution.cpp",
        "document_source_analyze_shard_key_read_write_distribution_gen",
        "document_source_visitor_docs_needed_bounds.cpp",
        "drop_agg_temp_collections.cpp",
        "metadata_consistency_util.cpp",
        "metadata_manager.cpp",
        "migration_batch_fetcher.cpp",
        "migration_batch_inserter.cpp",
        "migration_chunk_cloner_source.cpp",
        "migration_chunk_cloner_source_op_observer.cpp",
        "migration_coordinator.cpp",
        "migration_coordinator_document_gen",
        "migration_destination_manager.cpp",
        "migration_recipient_recovery_document_gen",
        "migration_session_id.cpp",
        "migration_source_manager.cpp",
        "migration_util.cpp",
        "move_timing_helper.cpp",
        "namespace_metadata_change_notifications.cpp",
        "query_analysis_coordinator.cpp",
        "query_analysis_op_observer.cpp",
        "query_analysis_op_observer_configsvr.cpp",
        "query_analysis_op_observer_rs.cpp",
        "query_analysis_op_observer_shardsvr.cpp",
        "range_deleter_service.cpp",
        "range_deleter_service_op_observer.cpp",
        "range_deletion_task_gen",
        "range_deletion_util.cpp",
        "read_only_catalog_cache_loader.cpp",
        "session_catalog_migration.cpp",
        "session_catalog_migration_destination.cpp",
        "session_catalog_migration_source.cpp",
        "shard_filtering_metadata_refresh.cpp",
        "shard_identity_rollback_notifier.cpp",
        "shard_key_util.cpp",
        "shard_local.cpp",
        "shard_metadata_util.cpp",
        "shard_server_catalog_cache_loader_impl.cpp",
        "shard_server_op_observer.cpp",
        "sharding_initialization_mongod.cpp",
        "sharding_ready.cpp",
        "sharding_recovery_service.cpp",
        "split_chunk.cpp",
        "split_vector.cpp",
        "start_chunk_clone_request.cpp",
        "type_shard_collection.cpp",
        "type_shard_database.cpp",
        ":collection_critical_section_document_gen",
        ":commit_chunk_migration_gen",
        ":sharding_runtime_d_params_gen",
        ":type_shard_collection_gen",
        ":type_shard_database_gen",
        "//src/mongo/db/s/metrics:phase_duration.cpp",
        "//src/mongo/db/s/metrics:sharding_data_transform_cumulative_metrics.cpp",
        "//src/mongo/db/s/metrics:sharding_data_transform_instance_metrics.cpp",
        "//src/mongo/db/s/metrics:sharding_data_transform_metrics.cpp",
        "//src/mongo/db/s/metrics:sharding_data_transform_metrics_observer.cpp",
        "//src/mongo/db/s/metrics/field_names:sharding_data_transform_cumulative_metrics_field_name_provider.cpp",
        "//src/mongo/db/s/metrics/field_names:sharding_data_transform_instance_metrics_field_name_provider.cpp",
        "//src/mongo/db/s/primary_only_service_helpers:cancel_state.cpp",
        "//src/mongo/db/s/primary_only_service_helpers:phase_transition_progress_gen",
        "//src/mongo/db/s/primary_only_service_helpers:retry_until_majority_commit.cpp",
        "//src/mongo/db/s/primary_only_service_helpers:retry_until_success_or_cancel.cpp",
        "//src/mongo/db/s/resharding:coordinator_document_gen",
        "//src/mongo/db/s/resharding:document_source_resharding_add_resume_id.cpp",
        "//src/mongo/db/s/resharding:document_source_resharding_iterate_transaction.cpp",
        "//src/mongo/db/s/resharding:document_source_resharding_ownership_match.cpp",
        "//src/mongo/db/s/resharding:donor_document_gen",
        "//src/mongo/db/s/resharding:donor_oplog_id_gen",
        "//src/mongo/db/s/resharding:recipient_document_gen",
        "//src/mongo/db/s/resharding:recipient_resume_document_gen",
        "//src/mongo/db/s/resharding:resharding_change_event_o2_field_gen",
        "//src/mongo/db/s/resharding:resharding_collection_cloner.cpp",
        "//src/mongo/db/s/resharding:resharding_coordinator_commit_monitor.cpp",
        "//src/mongo/db/s/resharding:resharding_coordinator_observer.cpp",
        "//src/mongo/db/s/resharding:resharding_coordinator_service.cpp",
        "//src/mongo/db/s/resharding:resharding_cumulative_metrics.cpp",
        "//src/mongo/db/s/resharding:resharding_cumulative_metrics_field_name_provider.cpp",
        "//src/mongo/db/s/resharding:resharding_data_copy_util.cpp",
        "//src/mongo/db/s/resharding:resharding_data_replication.cpp",
        "//src/mongo/db/s/resharding:resharding_donor_oplog_iterator.cpp",
        "//src/mongo/db/s/resharding:resharding_donor_recipient_common.cpp",
        "//src/mongo/db/s/resharding:resharding_donor_service.cpp",
        "//src/mongo/db/s/resharding:resharding_future_util.cpp",
        "//src/mongo/db/s/resharding:resharding_manual_cleanup.cpp",
        "//src/mongo/db/s/resharding:resharding_metrics.cpp",
        "//src/mongo/db/s/resharding:resharding_metrics_field_name_provider.cpp",
        "//src/mongo/db/s/resharding:resharding_metrics_helpers.cpp",
        "//src/mongo/db/s/resharding:resharding_op_observer.cpp",
        "//src/mongo/db/s/resharding:resharding_oplog_application.cpp",
        "//src/mongo/db/s/resharding:resharding_oplog_applier.cpp",
        "//src/mongo/db/s/resharding:resharding_oplog_applier_metrics.cpp",
        "//src/mongo/db/s/resharding:resharding_oplog_applier_progress_gen",
        "//src/mongo/db/s/resharding:resharding_oplog_batch_applier.cpp",
        "//src/mongo/db/s/resharding:resharding_oplog_batch_preparer.cpp",
        "//src/mongo/db/s/resharding:resharding_oplog_fetcher.cpp",
        "//src/mongo/db/s/resharding:resharding_oplog_fetcher_progress_gen",
        "//src/mongo/db/s/resharding:resharding_oplog_session_application.cpp",
        "//src/mongo/db/s/resharding:resharding_recipient_service.cpp",
        "//src/mongo/db/s/resharding:resharding_recipient_service_external_state.cpp",
        "//src/mongo/db/s/resharding:resharding_txn_cloner.cpp",
        "//src/mongo/db/s/resharding:resharding_txn_cloner_progress_gen",
        "//src/mongo/db/s/resharding:resharding_util.cpp",
    ],
    hdrs = [
        "active_migrations_registry.h",
        "analyze_shard_key_read_write_distribution.h",
        "auto_split_vector.h",
        "chunk_move_write_concern_options.h",
        "chunk_operation_precondition_checks.h",
        "collection_sharding_runtime.h",
        "collection_sharding_state_factory_shard.h",
        "config_server_op_observer.h",
        "document_source_analyze_shard_key_read_write_distribution.h",
        "drop_agg_temp_collections.h",
        "metadata_consistency_util.h",
        "metadata_manager.h",
        "migration_batch_fetcher.h",
        "migration_batch_inserter.h",
        "migration_chunk_cloner_source.h",
        "migration_chunk_cloner_source_op_observer.h",
        "migration_coordinator.h",
        "migration_destination_manager.h",
        "migration_session_id.h",
        "migration_source_manager.h",
        "migration_util.h",
        "move_timing_helper.h",
        "namespace_metadata_change_notifications.h",
        "query_analysis_coordinator.h",
        "query_analysis_op_observer.h",
        "query_analysis_op_observer_configsvr.h",
        "query_analysis_op_observer_rs.h",
        "query_analysis_op_observer_shardsvr.h",
        "range_deleter_service.h",
        "range_deleter_service_op_observer.h",
        "range_deletion_util.h",
        "read_only_catalog_cache_loader.h",
        "session_catalog_migration.h",
        "session_catalog_migration_destination.h",
        "session_catalog_migration_source.h",
        "shard_filtering_metadata_refresh.h",
        "shard_identity_rollback_notifier.h",
        "shard_key_util.h",
        "shard_local.h",
        "shard_metadata_util.h",
        "shard_server_catalog_cache_loader.h",
        "shard_server_catalog_cache_loader_impl.h",
        "shard_server_op_observer.h",
        "sharding_initialization_mongod.h",
        "sharding_ready.h",
        "sharding_recovery_service.h",
        "split_chunk.h",
        "split_vector.h",
        "start_chunk_clone_request.h",
        "type_shard_collection.h",
        "type_shard_database.h",
        "//src/mongo/db/commands:list_indexes_allowed_fields.h",
        "//src/mongo/db/s:migration_batch_mock_inserter.h",
        "//src/mongo/db/s/metrics:cumulative_metrics_state_holder.h",
        "//src/mongo/db/s/metrics:metrics_state_holder.h",
        "//src/mongo/db/s/metrics:phase_duration.h",
        "//src/mongo/db/s/metrics:sharding_data_transform_cumulative_metrics.h",
        "//src/mongo/db/s/metrics:sharding_data_transform_instance_metrics.h",
        "//src/mongo/db/s/metrics:sharding_data_transform_metrics.h",
        "//src/mongo/db/s/metrics:sharding_data_transform_metrics_observer.h",
        "//src/mongo/db/s/metrics:sharding_data_transform_metrics_observer_interface.h",
        "//src/mongo/db/s/metrics:with_oplog_application_count_metrics.h",
        "//src/mongo/db/s/metrics:with_oplog_application_count_metrics_also_updating_cumulative_metrics.h",
        "//src/mongo/db/s/metrics:with_oplog_application_latency_metrics.h",
        "//src/mongo/db/s/metrics:with_oplog_application_latency_metrics_interface_updating_cumulative_metrics.h",
        "//src/mongo/db/s/metrics:with_phase_duration_management.h",
        "//src/mongo/db/s/metrics:with_state_management_for_cumulative_metrics.h",
        "//src/mongo/db/s/metrics:with_state_management_for_instance_metrics.h",
        "//src/mongo/db/s/metrics:with_typed_cumulative_metrics_provider.h",
        "//src/mongo/db/s/metrics/field_names:sharding_data_transform_cumulative_metrics_field_name_provider.h",
        "//src/mongo/db/s/metrics/field_names:sharding_data_transform_instance_metrics_field_name_provider.h",
        "//src/mongo/db/s/metrics/field_names:with_document_copy_approximation_field_name_overrides.h",
        "//src/mongo/db/s/metrics/field_names:with_document_copy_count_field_name_overrides.h",
        "//src/mongo/db/s/metrics/field_names:with_oplog_application_count_metrics_field_names.h",
        "//src/mongo/db/s/metrics/field_names:with_oplog_application_latency_metrics_field_names.h",
        "//src/mongo/db/s/primary_only_service_helpers:cancel_state.h",
        "//src/mongo/db/s/primary_only_service_helpers:retry_until_majority_commit.h",
        "//src/mongo/db/s/primary_only_service_helpers:retry_until_success_or_cancel.h",
        "//src/mongo/db/s/primary_only_service_helpers:retrying_cancelable_operation_context_factory.h",
        "//src/mongo/db/s/primary_only_service_helpers:with_automatic_retry.h",
        "//src/mongo/db/s/resharding:document_source_resharding_add_resume_id.h",
        "//src/mongo/db/s/resharding:document_source_resharding_iterate_transaction.h",
        "//src/mongo/db/s/resharding:document_source_resharding_ownership_match.h",
        "//src/mongo/db/s/resharding:resharding_collection_cloner.h",
        "//src/mongo/db/s/resharding:resharding_coordinator_commit_monitor.h",
        "//src/mongo/db/s/resharding:resharding_coordinator_observer.h",
        "//src/mongo/db/s/resharding:resharding_coordinator_service.h",
        "//src/mongo/db/s/resharding:resharding_cumulative_metrics.h",
        "//src/mongo/db/s/resharding:resharding_cumulative_metrics_field_name_provider.h",
        "//src/mongo/db/s/resharding:resharding_data_copy_util.h",
        "//src/mongo/db/s/resharding:resharding_data_replication.h",
        "//src/mongo/db/s/resharding:resharding_donor_oplog_iterator.h",
        "//src/mongo/db/s/resharding:resharding_donor_recipient_common.h",
        "//src/mongo/db/s/resharding:resharding_donor_service.h",
        "//src/mongo/db/s/resharding:resharding_future_util.h",
        "//src/mongo/db/s/resharding:resharding_manual_cleanup.h",
        "//src/mongo/db/s/resharding:resharding_metrics.h",
        "//src/mongo/db/s/resharding:resharding_metrics_field_name_provider.h",
        "//src/mongo/db/s/resharding:resharding_metrics_helpers.h",
        "//src/mongo/db/s/resharding:resharding_op_observer.h",
        "//src/mongo/db/s/resharding:resharding_oplog_application.h",
        "//src/mongo/db/s/resharding:resharding_oplog_applier.h",
        "//src/mongo/db/s/resharding:resharding_oplog_applier_metrics.h",
        "//src/mongo/db/s/resharding:resharding_oplog_batch_applier.h",
        "//src/mongo/db/s/resharding:resharding_oplog_batch_preparer.h",
        "//src/mongo/db/s/resharding:resharding_oplog_fetcher.h",
        "//src/mongo/db/s/resharding:resharding_oplog_session_application.h",
        "//src/mongo/db/s/resharding:resharding_recipient_service.h",
        "//src/mongo/db/s/resharding:resharding_recipient_service_external_state.h",
        "//src/mongo/db/s/resharding:resharding_txn_cloner.h",
        "//src/mongo/db/s/resharding:resharding_util.h",
    ],
    tags = [
        "compile_requires_large_memory_gcc",
        "compile_requires_large_memory_sanitizer",
    ],
    deps = [
        ":analyze_shard_key_util",
        ":balancer_stats_registry",
        ":forwardable_operation_metadata",
        ":query_analysis_writer",
        ":resharding_server_parameters_idl",
        ":sharding_catalog",
        ":sharding_catalog_manager",
        ":sharding_logging",
        ":transaction_coordinator",
        "//src/mongo/client:clientdriver_minimal",
        "//src/mongo/client:remote_command_targeter",
        "//src/mongo/crypto:encrypted_field_config",
        "//src/mongo/crypto:fle_crypto",
        "//src/mongo/db:cloner",
        "//src/mongo/db:coll_mod_command_idl",
        "//src/mongo/db:dbhelpers",
        "//src/mongo/db:index_commands_idl",
        "//src/mongo/db:internal_transactions_feature_flag",
        "//src/mongo/db:keys_collection_client_direct",
        "//src/mongo/db:metadata_consistency_types_idl",
        "//src/mongo/db:rs_local_client",
        "//src/mongo/db:rw_concern_d",
        "//src/mongo/db:server_base",
        "//src/mongo/db:shard_role",
        "//src/mongo/db:vector_clock_mongod",
        "//src/mongo/db/auth:user_cache_invalidator",
        "//src/mongo/db/catalog:catalog_helpers",
        "//src/mongo/db/catalog:index_key_validate",
        "//src/mongo/db/collection_crud",
        "//src/mongo/db/commands:mongod_fcv",
        "//src/mongo/db/commands:notify_sharding_event_idl",
        "//src/mongo/db/concurrency:exception_util",
        "//src/mongo/db/index_builds:index_builds_coordinator",
        "//src/mongo/db/index_builds:multi_index_block",
        "//src/mongo/db/op_observer",
        "//src/mongo/db/op_observer:batched_write_context",
        "//src/mongo/db/op_observer:op_observer_impl",
        "//src/mongo/db/op_observer:op_observer_util",
        "//src/mongo/db/pipeline:aggregation_request_helper",
        "//src/mongo/db/pipeline:docs_needed_bounds_visitor",
        "//src/mongo/db/query/client_cursor",
        "//src/mongo/db/query/write_ops",
        "//src/mongo/db/query/write_ops:write_ops_exec",
        "//src/mongo/db/repl:abstract_async_component",
        "//src/mongo/db/repl:change_stream_oplog_notification",
        "//src/mongo/db/repl:image_collection_entry",
        "//src/mongo/db/repl:oplog",
        "//src/mongo/db/repl:primary_only_service",
        "//src/mongo/db/repl:replica_set_aware_service",
        "//src/mongo/db/repl:wait_for_majority_service",
        "//src/mongo/db/session:session_catalog_mongod",
        "//src/mongo/db/timeseries/bucket_catalog",
        "//src/mongo/db/transaction",
        "//src/mongo/db/transaction:transaction_operations",
        "//src/mongo/executor:async_rpc",
        "//src/mongo/executor:inline_executor",
        "//src/mongo/s:common_s",
        "//src/mongo/s:sharding_api",
        "//src/mongo/s:sharding_initialization",
        "//src/mongo/s/query/planner:cluster_aggregate",
        "//src/mongo/util:future_util",
        "//src/mongo/util:log_and_backoff",
        "//src/mongo/util/concurrency:ticketholder",
    ],
)

mongo_cc_library(
    name = "sharding_mongod_test_fixture",
    srcs = [
        "sharding_mongod_test_fixture.cpp",
    ],
    hdrs = [
        "sharding_mongod_test_fixture.h",
    ],
    deps = [
        ":sharding_runtime_d",
        "//src/mongo/db:service_context_d_test_fixture",
        "//src/mongo/db/op_observer",
        "//src/mongo/db/op_observer:op_observer_impl",
        "//src/mongo/db/op_observer:operation_logger_impl",
        "//src/mongo/db/repl:replmocks",
        "//src/mongo/db/repl:storage_interface_impl",
        "//src/mongo/db/session:session_catalog_mongod",
        "//src/mongo/s:sharding_test_fixture_common",
    ],
)

mongo_cc_library(
    name = "shard_server_test_fixture",
    srcs = [
        "shard_server_test_fixture.cpp",
    ],
    hdrs = [
        "shard_server_test_fixture.h",
    ],
    deps = [
        ":sharding_mongod_test_fixture",
        "//src/mongo/s/catalog:sharding_catalog_client_impl",
    ],
)

mongo_cc_library(
    name = "config_server_test_fixture",
    srcs = [
        "//src/mongo/db/s/config:config_server_test_fixture.cpp",
    ],
    hdrs = [
        "//src/mongo/db/s/config:config_server_test_fixture.h",
    ],
    deps = [
        ":sharding_mongod_test_fixture",
        "//src/mongo/db/op_observer",
        "//src/mongo/db/op_observer:op_observer_impl",
        "//src/mongo/db/op_observer:operation_logger_impl",
        "//src/mongo/s/catalog:sharding_catalog_client_impl",
    ],
)

mongo_cc_library(
    name = "sharding_commands_d",
    srcs = [
        "analyze_shard_key_cmd.cpp",
        "analyze_shard_key_cmd_util.cpp",
        "auto_split_vector_command.cpp",
        "check_sharding_index_command.cpp",
        "cleanup_orphaned_cmd.cpp",
        "cleanup_structured_encryption_data_coordinator.cpp",
        "cleanup_structured_encryption_data_coordinator_gen",
        "clone_catalog_data_command.cpp",
        "cluster_abort_transaction_cmd_d.cpp",
        "cluster_commit_transaction_cmd_d.cpp",
        "collmod_coordinator.cpp",
        "collmod_coordinator_document_gen",
        "compact_structured_encryption_data_coordinator.cpp",
        "compact_structured_encryption_data_coordinator_gen",
        "configure_query_analyzer_cmd.cpp",
        "convert_to_capped_coordinator.cpp",
        "convert_to_capped_coordinator_document_gen",
        "create_collection_coordinator.cpp",
        "create_collection_coordinator_document_gen",
        "create_database_coordinator.cpp",
        "create_database_coordinator_document_gen",
        "drop_collection_coordinator.cpp",
        "drop_collection_coordinator_document_gen",
        "drop_database_coordinator.cpp",
        "drop_database_coordinator_document_gen",
        "flush_database_cache_updates_command.cpp",
        "flush_resharding_state_change_command.cpp",
        "flush_routing_table_cache_updates_command.cpp",
        "get_database_version_command.cpp",
        "get_shard_version_command.cpp",
        "get_sharding_ready_command.cpp",
        "migration_chunk_cloner_source_commands.cpp",
        "migration_destination_manager_commands.cpp",
        "move_primary_coordinator.cpp",
        "move_primary_coordinator_document_gen",
        "refine_collection_shard_key_coordinator.cpp",
        "refine_collection_shard_key_coordinator_document_gen",
        "refresh_query_analyzer_configuration_cmd.cpp",
        "remove_shard_commit_coordinator.cpp",
        "remove_shard_commit_coordinator_document_gen",
        "rename_collection_coordinator.cpp",
        "rename_collection_participant_service.cpp",
        "reshard_collection_coordinator.cpp",
        "resharding_test_commands.cpp",
        "set_allow_migrations_coordinator.cpp",
        "sharded_index_consistency_server_status.cpp",
        "sharding_ddl_coordinator.cpp",
        "sharding_ddl_coordinator_external_state.cpp",
        "sharding_ddl_coordinator_service.cpp",
        "sharding_server_status.cpp",
        "sharding_state_command.cpp",
        "shardsvr_abort_reshard_collection_command.cpp",
        "shardsvr_add_shard_cmd.cpp",
        "shardsvr_change_primary_command.cpp",
        "shardsvr_check_metadata_consistency_command.cpp",
        "shardsvr_check_metadata_consistency_participant_command.cpp",
        "shardsvr_cleanup_reshard_collection_command.cpp",
        "shardsvr_cleanup_structured_encryption_data_command.cpp",
        "shardsvr_collmod_command.cpp",
        "shardsvr_collmod_participant_command.cpp",
        "shardsvr_commit_index_participant_command.cpp",
        "shardsvr_commit_reshard_collection_command.cpp",
        "shardsvr_compact_structured_encryption_data_command.cpp",
        "shardsvr_convert_to_capped_command.cpp",
        "shardsvr_convert_to_capped_participant_command.cpp",
        "shardsvr_create_collection_command.cpp",
        "shardsvr_create_collection_participant_command.cpp",
        "shardsvr_drop_collection_command.cpp",
        "shardsvr_drop_collection_if_uuid_not_matching_command.cpp",
        "shardsvr_drop_collection_participant_command.cpp",
        "shardsvr_drop_database_command.cpp",
        "shardsvr_drop_database_participant_command.cpp",
        "shardsvr_drop_index_catalog_entry_participant_command.cpp",
        "shardsvr_drop_indexes_command.cpp",
        "shardsvr_get_stats_for_balancing_command.cpp",
        "shardsvr_index_catalog_test_commands.cpp",
        "shardsvr_join_ddl_coordinators_command.cpp",
        "shardsvr_join_migrations_command.cpp",
        "shardsvr_merge_all_chunks_on_shard_command.cpp",
        "shardsvr_merge_chunks_command.cpp",
        "shardsvr_move_primary_command.cpp",
        "shardsvr_move_primary_enter_critical_section_command.cpp",
        "shardsvr_move_primary_exit_critical_section_command.cpp",
        "shardsvr_move_range_command.cpp",
        "shardsvr_notify_sharding_event_command.cpp",
        "shardsvr_participant_block_command.cpp",
        "shardsvr_refine_collection_shard_key_command.cpp",
        "shardsvr_rename_collection_command.cpp",
        "shardsvr_rename_collection_participant_command.cpp",
        "shardsvr_rename_index_metadata_command.cpp",
        "shardsvr_reshard_collection_command.cpp",
        "shardsvr_resharding_operation_time_command.cpp",
        "shardsvr_set_allow_migrations_command.cpp",
        "shardsvr_set_cluster_parameter_command.cpp",
        "shardsvr_set_user_write_block_mode_command.cpp",
        "shardsvr_split_chunk_command.cpp",
        "shardsvr_untrack_unsplittable_collection_command.cpp",
        "shardsvr_validate_shard_key_candidate.cpp",
        "split_vector_command.cpp",
        "transition_to_sharded_cluster_command.cpp",
        "txn_two_phase_commit_cmds.cpp",
        "untrack_unsplittable_collection_coordinator.cpp",
        ":remove_chunks_gen",
        ":reshard_collection_coordinator_document_gen",
        ":resharding_test_commands_gen",
        ":set_allow_migrations_coordinator_document_gen",
        ":sharded_collmod_gen",
        ":sharded_rename_collection_gen",
        ":sharding_ddl_coordinator_gen",
        ":transition_to_sharded_cluster_gen",
        ":untrack_unsplittable_collection_coordinator_document_gen",
        "//src/mongo/db/s/config:configsvr_abort_reshard_collection_command.cpp",
        "//src/mongo/db/s/config:configsvr_add_shard_command.cpp",
        "//src/mongo/db/s/config:configsvr_add_shard_to_zone_command.cpp",
        "//src/mongo/db/s/config:configsvr_balancer_collection_status_command.cpp",
        "//src/mongo/db/s/config:configsvr_check_cluster_metadata_consistency_command.cpp",
        "//src/mongo/db/s/config:configsvr_check_metadata_consistency_command.cpp",
        "//src/mongo/db/s/config:configsvr_cleanup_reshard_collection_command.cpp",
        "//src/mongo/db/s/config:configsvr_clear_jumbo_flag_command.cpp",
        "//src/mongo/db/s/config:configsvr_collmod_command.cpp",
        "//src/mongo/db/s/config:configsvr_commit_chunk_migration_command.cpp",
        "//src/mongo/db/s/config:configsvr_commit_index_command.cpp",
        "//src/mongo/db/s/config:configsvr_commit_move_primary_command.cpp",
        "//src/mongo/db/s/config:configsvr_commit_refine_collection_shard_key.cpp",
        "//src/mongo/db/s/config:configsvr_commit_reshard_collection_command.cpp",
        "//src/mongo/db/s/config:configsvr_configure_collection_balancing.cpp",
        "//src/mongo/db/s/config:configsvr_control_balancer_command.cpp",
        "//src/mongo/db/s/config:configsvr_coordinator.cpp",
        "//src/mongo/db/s/config:configsvr_coordinator_gen",
        "//src/mongo/db/s/config:configsvr_coordinator_service.cpp",
        "//src/mongo/db/s/config:configsvr_create_database_command.cpp",
        "//src/mongo/db/s/config:configsvr_drop_index_catalog_command.cpp",
        "//src/mongo/db/s/config:configsvr_ensure_chunk_version_is_greater_than_command.cpp",
        "//src/mongo/db/s/config:configsvr_get_historical_placement_info.cpp",
        "//src/mongo/db/s/config:configsvr_merge_all_chunks_on_shard_command.cpp",
        "//src/mongo/db/s/config:configsvr_merge_chunks_command.cpp",
        "//src/mongo/db/s/config:configsvr_move_range_command.cpp",
        "//src/mongo/db/s/config:configsvr_remove_chunks_command.cpp",
        "//src/mongo/db/s/config:configsvr_remove_shard_command.cpp",
        "//src/mongo/db/s/config:configsvr_remove_shard_from_zone_command.cpp",
        "//src/mongo/db/s/config:configsvr_remove_tags_command.cpp",
        "//src/mongo/db/s/config:configsvr_repair_sharded_collection_chunks_history_command.cpp",
        "//src/mongo/db/s/config:configsvr_reset_placement_history_command.cpp",
        "//src/mongo/db/s/config:configsvr_reshard_collection_cmd.cpp",
        "//src/mongo/db/s/config:configsvr_run_restore_command.cpp",
        "//src/mongo/db/s/config:configsvr_set_allow_migrations_command.cpp",
        "//src/mongo/db/s/config:configsvr_set_cluster_parameter_command.cpp",
        "//src/mongo/db/s/config:configsvr_set_user_write_block_mode_command.cpp",
        "//src/mongo/db/s/config:configsvr_split_chunk_command.cpp",
        "//src/mongo/db/s/config:configsvr_transition_from_dedicated_config_server_command.cpp",
        "//src/mongo/db/s/config:configsvr_transition_to_dedicated_config_server_command.cpp",
        "//src/mongo/db/s/config:configsvr_update_zone_key_range_command.cpp",
        "//src/mongo/db/s/config:set_cluster_parameter_coordinator.cpp",
        "//src/mongo/db/s/config:set_cluster_parameter_coordinator_document_gen",
        "//src/mongo/db/s/config:set_user_write_block_mode_coordinator.cpp",
        "//src/mongo/db/s/config:set_user_write_block_mode_coordinator_document_gen",
        "//src/mongo/db/s/migration_blocking_operation:migration_blocking_operation_coordinator.cpp",
        "//src/mongo/db/s/migration_blocking_operation:migration_blocking_operation_coordinator_gen",
        "//src/mongo/db/s/migration_blocking_operation:multi_update_coordinator.cpp",
        "//src/mongo/db/s/migration_blocking_operation:multi_update_coordinator_external_state.cpp",
        "//src/mongo/db/s/migration_blocking_operation:multi_update_coordinator_gen",
        "//src/mongo/db/s/migration_blocking_operation:multi_update_coordinator_server_parameters_gen",
        "//src/mongo/db/s/migration_blocking_operation:shardsvr_begin_migration_blocking_operation.cpp",
        "//src/mongo/db/s/migration_blocking_operation:shardsvr_coordinate_multi_update_command.cpp",
        "//src/mongo/db/s/migration_blocking_operation:shardsvr_end_migration_blocking_operation.cpp",
        "//src/mongo/db/s/query_cmd:cluster_bulk_write_cmd_d.cpp",
        "//src/mongo/db/s/query_cmd:cluster_count_cmd_d.cpp",
        "//src/mongo/db/s/query_cmd:cluster_find_cmd_d.cpp",
        "//src/mongo/db/s/query_cmd:cluster_getmore_cmd_d.cpp",
        "//src/mongo/db/s/query_cmd:cluster_pipeline_cmd_d.cpp",
        "//src/mongo/db/s/query_cmd:cluster_write_cmd_d.cpp",
    ],
    hdrs = [
        "analyze_shard_key_cmd_util.h",
        "cleanup_structured_encryption_data_coordinator.h",
        "collmod_coordinator.h",
        "compact_structured_encryption_data_coordinator.h",
        "convert_to_capped_coordinator.h",
        "create_collection_coordinator.h",
        "create_database_coordinator.h",
        "drop_collection_coordinator.h",
        "drop_database_coordinator.h",
        "move_primary_coordinator.h",
        "refine_collection_shard_key_coordinator.h",
        "remove_shard_commit_coordinator.h",
        "rename_collection_coordinator.h",
        "rename_collection_participant_service.h",
        "reshard_collection_coordinator.h",
        "set_allow_migrations_coordinator.h",
        "sharding_ddl_coordinator.h",
        "sharding_ddl_coordinator_external_state.h",
        "sharding_ddl_coordinator_service.h",
        "untrack_unsplittable_collection_coordinator.h",
        "//src/mongo/db/query/query_stats:count_key.h",
        "//src/mongo/db/s/config:configsvr_coordinator.h",
        "//src/mongo/db/s/config:configsvr_coordinator_service.h",
        "//src/mongo/db/s/config:known_collections.h",
        "//src/mongo/db/s/config:set_cluster_parameter_coordinator.h",
        "//src/mongo/db/s/config:set_user_write_block_mode_coordinator.h",
        "//src/mongo/db/s/migration_blocking_operation:migration_blocking_operation_coordinator.h",
        "//src/mongo/db/s/migration_blocking_operation:multi_update_coordinator.h",
        "//src/mongo/db/s/migration_blocking_operation:multi_update_coordinator_external_state.h",
        "//src/mongo/db/s/primary_only_service_helpers:pause_during_phase_transition_fail_point.h",
        "//src/mongo/s/commands:cluster_abort_transaction_cmd.h",
        "//src/mongo/s/commands:cluster_commit_transaction_cmd.h",
        "//src/mongo/s/commands/query_cmd:cluster_bulk_write_cmd.h",
        "//src/mongo/s/commands/query_cmd:cluster_count_cmd.h",
        "//src/mongo/s/commands/query_cmd:cluster_find_cmd.h",
        "//src/mongo/s/commands/query_cmd:cluster_getmore_cmd.h",
        "//src/mongo/s/commands/query_cmd:cluster_pipeline_cmd.h",
    ],
    tags = ["compile_requires_large_memory_gcc"],
    deps = [
        ":analyze_shard_key_util",
        ":balancer_stats_registry",
        ":forwardable_operation_metadata",
        ":sharding_catalog",
        ":sharding_logging",
        ":sharding_runtime_d",
        ":user_writes_recoverable_critical_section",
        "//src/mongo/db:cloner",
        "//src/mongo/db:cluster_transaction_api",
        "//src/mongo/db:coll_mod_command_idl",
        "//src/mongo/db:fle_crud",
        "//src/mongo/db:index_commands_idl",
        "//src/mongo/db:internal_transactions_feature_flag",
        "//src/mongo/db:multitenancy",
        "//src/mongo/db:server_feature_flags",
        "//src/mongo/db/catalog:catalog_helpers",
        "//src/mongo/db/catalog:collection_uuid_mismatch_info",
        "//src/mongo/db/catalog:database_holder",
        "//src/mongo/db/commands:cluster_server_parameter_commands_invocation",
        "//src/mongo/db/commands:core",
        "//src/mongo/db/commands:create_command",
        "//src/mongo/db/commands:list_collections_filter",
        "//src/mongo/db/commands:mongod_fcv",
        "//src/mongo/db/commands:notify_sharding_event_idl",
        "//src/mongo/db/commands:rename_collection_idl",
        "//src/mongo/db/commands:server_status_core",
        "//src/mongo/db/commands:set_user_write_block_mode_idl",
        "//src/mongo/db/commands:test_commands_enabled",
        "//src/mongo/db/commands:txn_cmd_request",
        "//src/mongo/db/index_builds:index_builds_coordinator",
        "//src/mongo/db/pipeline/process_interface:shardsvr_process_interface",
        "//src/mongo/db/query/bson:dotted_path_support",
        "//src/mongo/db/query/query_settings:utils",
        "//src/mongo/db/repl:change_stream_oplog_notification",
        "//src/mongo/db/repl:primary_only_service",
        "//src/mongo/db/repl:repl_coordinator_interface",
        "//src/mongo/db/repl:replica_set_messages",
        "//src/mongo/db/repl:wait_for_majority_service",
        "//src/mongo/db/session:session_catalog_mongod",
        "//src/mongo/db/timeseries:catalog_helper",
        "//src/mongo/db/timeseries:timeseries_collmod",
        "//src/mongo/db/timeseries:timeseries_conversion_util",
        "//src/mongo/db/timeseries:timeseries_options",
        "//src/mongo/db/transaction:transaction_api",
        "//src/mongo/executor:async_rpc",
        "//src/mongo/executor:inline_executor",
        "//src/mongo/idl:cluster_server_parameter",
        "//src/mongo/idl:cluster_server_parameter_server_status",
        "//src/mongo/s:common_s",
        "//src/mongo/s:sharding_router_api",
        "//src/mongo/s:startup_initialization",
        "//src/mongo/s/commands:cluster_commands_common",
        "//src/mongo/s/commands:sharded_cluster_sharding_commands",
    ],
)

mongo_cc_unit_test(
    name = "shard_server_op_observer_test",
    srcs = [
        "shard_server_op_observer_test.cpp",
    ],
    tags = ["mongo_unittest_fourth_group"],
    deps = [
        ":sharding_runtime_d",
        "//src/mongo/db:service_context_d_test_fixture",
        "//src/mongo/db/auth:authmocks",
        "//src/mongo/db/op_observer:op_observer_util",
        "//src/mongo/db/repl:replmocks",
        "//src/mongo/db/repl:storage_interface_impl",
        "//src/mongo/idl:server_parameter_test_util",
    ],
)

mongo_cc_unit_test(
    name = "db_s_shard_server_test",
    srcs = [
        "active_migrations_registry_test.cpp",
        "analyze_shard_key_read_write_distribution_test.cpp",
        "auto_split_vector_test.cpp",
        "collection_metadata_filtering_test.cpp",
        "collection_metadata_test.cpp",
        "collection_sharding_runtime_test.cpp",
        "database_sharding_state_test.cpp",
        "ddl_lock_manager_test.cpp",
        "implicit_collection_creation_test.cpp",
        "metadata_consistency_util_test.cpp",
        "metadata_manager_test.cpp",
        "migration_batch_fetcher_test.cpp",
        "migration_chunk_cloner_source_test.cpp",
        "migration_destination_manager_test.cpp",
        "migration_session_id_test.cpp",
        "migration_util_test.cpp",
        "namespace_metadata_change_notifications_test.cpp",
        "op_observer_sharding_test.cpp",
        "operation_sharding_state_test.cpp",
        "persistent_task_queue.h",
        "persistent_task_queue_test.cpp",
        "query_analysis_writer_test.cpp",
        "range_arithmetic_test.cpp",
        "range_deleter_service_op_observer_test.cpp",
        "range_deleter_service_test.cpp",
        "range_deleter_service_test.h",
        "range_deleter_service_test_util.cpp",
        "range_deletion_util_test.cpp",
        "session_catalog_migration_destination_test.cpp",
        "session_catalog_migration_source_test.cpp",
        "shard_key_index_util_test.cpp",
        "shard_local_test.cpp",
        "shard_metadata_util_test.cpp",
        "shard_server_catalog_cache_loader_test.cpp",
        "sharding_ddl_coordinator_external_state_for_test.cpp",
        "sharding_ddl_coordinator_external_state_for_test.h",
        "sharding_ddl_coordinator_service_test.cpp",
        "sharding_ddl_coordinator_test.cpp",
        "sharding_initialization_mongod_test.cpp",
        "sharding_initialization_op_observer_test.cpp",
        "sharding_logging_test.cpp",
        "sharding_recovery_service_test.cpp",
        "sharding_test_helpers.h",
        "split_chunk_request_test.cpp",
        "split_vector_test.cpp",
        "start_chunk_clone_request_test.cpp",
        "transaction_coordinator_catalog_test.cpp",
        "transaction_coordinator_futures_util_test.cpp",
        "transaction_coordinator_service_test.cpp",
        "transaction_coordinator_structures_test.cpp",
        "transaction_coordinator_test.cpp",
        "transaction_coordinator_test_fixture.cpp",
        "transaction_coordinator_test_fixture.h",
        "type_shard_collection_test.cpp",
        "type_shard_identity_test.cpp",
        "vector_clock_shard_server_test.cpp",
        "//src/mongo/db/s/balancer:balance_stats_test.cpp",
        "//src/mongo/db/s/metrics:phase_duration_test.cpp",
        "//src/mongo/db/s/metrics:sharding_data_transform_cumulative_metrics_test.cpp",
        "//src/mongo/db/s/metrics:sharding_data_transform_instance_metrics_test.cpp",
        "//src/mongo/db/s/metrics:sharding_data_transform_metrics_test_fixture.h",
        "//src/mongo/db/s/migration_blocking_operation:migration_blocking_operation_coordinator_test.cpp",
        "//src/mongo/db/s/migration_blocking_operation:multi_update_coordinator_test.cpp",
        "//src/mongo/db/s/primary_only_service_helpers:cancel_state_test.cpp",
        "//src/mongo/db/s/resharding:resharding_agg_test.cpp",
        "//src/mongo/db/s/resharding:resharding_collection_cloner_test.cpp",
        "//src/mongo/db/s/resharding:resharding_collection_test.cpp",
        "//src/mongo/db/s/resharding:resharding_cumulative_metrics_test.cpp",
        "//src/mongo/db/s/resharding:resharding_data_replication_test.cpp",
        "//src/mongo/db/s/resharding:resharding_destined_recipient_test.cpp",
        "//src/mongo/db/s/resharding:resharding_donor_oplog_iterator_test.cpp",
        "//src/mongo/db/s/resharding:resharding_donor_recipient_common_test.cpp",
        "//src/mongo/db/s/resharding:resharding_donor_service_test.cpp",
        "//src/mongo/db/s/resharding:resharding_future_util_test.cpp",
        "//src/mongo/db/s/resharding:resharding_metrics_test.cpp",
        "//src/mongo/db/s/resharding:resharding_oplog_applier_metrics_test.cpp",
        "//src/mongo/db/s/resharding:resharding_oplog_applier_test.cpp",
        "//src/mongo/db/s/resharding:resharding_oplog_batch_applier_test.cpp",
        "//src/mongo/db/s/resharding:resharding_oplog_batch_preparer_test.cpp",
        "//src/mongo/db/s/resharding:resharding_oplog_crud_application_test.cpp",
        "//src/mongo/db/s/resharding:resharding_oplog_fetcher_test.cpp",
        "//src/mongo/db/s/resharding:resharding_oplog_session_application_test.cpp",
        "//src/mongo/db/s/resharding:resharding_recipient_service_external_state_test.cpp",
        "//src/mongo/db/s/resharding:resharding_recipient_service_test.cpp",
        "//src/mongo/db/s/resharding:resharding_service_test_helpers.h",
        "//src/mongo/db/s/resharding:resharding_txn_cloner_test.cpp",
    ],
    tags = [
        "compile_requires_large_memory_gcc",
        "mongo_unittest_second_group",
    ],
    deps = [
        ":analyze_shard_key_util",
        ":query_analysis_writer",
        ":shard_server_test_fixture",
        ":sharding_catalog",
        ":sharding_commands_d",
        ":sharding_logging",
        ":transaction_coordinator",
        "//src/mongo/client:remote_command_targeter_mock",
        "//src/mongo/db:coll_mod_command_idl",
        "//src/mongo/db:index_commands_idl",
        "//src/mongo/db:keys_collection_client_direct",
        "//src/mongo/db:query_expressions",
        "//src/mongo/db:read_write_concern_defaults_mock",
        "//src/mongo/db/auth:authmocks",
        "//src/mongo/db/catalog:catalog_helpers",
        "//src/mongo/db/catalog:catalog_test_fixture",
        "//src/mongo/db/commands:create_command",
        "//src/mongo/db/commands:list_collections_filter",
        "//src/mongo/db/exec/document_value:document_value_test_util",
        "//src/mongo/db/index_builds:index_builds_coordinator_mock",
        "//src/mongo/db/op_observer",
        "//src/mongo/db/op_observer:op_observer_impl",
        "//src/mongo/db/op_observer:op_observer_util",
        "//src/mongo/db/op_observer:operation_logger_impl",
        "//src/mongo/db/op_observer:operation_logger_mock",
        "//src/mongo/db/pipeline:aggregation_context_fixture",
        "//src/mongo/db/pipeline:document_source_mock",
        "//src/mongo/db/pipeline/process_interface:shardsvr_process_interface",
        "//src/mongo/db/query:query_request",
        "//src/mongo/db/query:query_test_service_context",
        "//src/mongo/db/query/write_ops:write_ops_exec",
        "//src/mongo/db/repl:image_collection_entry",
        "//src/mongo/db/repl:mock_repl_coord_server_fixture",
        "//src/mongo/db/repl:oplog_application",
        "//src/mongo/db/repl:oplog_interface_local",
        "//src/mongo/db/repl:primary_only_service_test_fixture",
        "//src/mongo/db/repl:replmocks",
        "//src/mongo/db/repl:storage_interface_impl",
        "//src/mongo/db/session:logical_session_cache_impl",
        "//src/mongo/db/session:logical_session_cache_noop",
        "//src/mongo/db/session:session_catalog_mongod",
        "//src/mongo/db/timeseries:timeseries_options",
        "//src/mongo/executor:thread_pool_task_executor_test_fixture",
        "//src/mongo/idl:server_parameter_test_util",
        "//src/mongo/s:sharding_mongos_test_fixture",
        "//src/mongo/s/catalog:sharding_catalog_client_mock",
    ],
)

mongo_cc_unit_test(
    name = "db_s_config_server_test",
    srcs = [
        "config_server_op_observer_test.cpp",
        "create_database_util_test.cpp",
        "query_analysis_coordinator_test.cpp",
        "sharding_catalog_client_aggregations_test.cpp",
        "sharding_ddl_util_test.cpp",
        "sharding_util_refresh_test.cpp",
        "topology_time_ticker_test.cpp",
        "vector_clock_config_server_test.cpp",
        "//src/mongo/db/s/balancer:auto_merger_policy_test.cpp",
        "//src/mongo/db/s/balancer:balancer_chunk_selection_policy_test.cpp",
        "//src/mongo/db/s/balancer:balancer_commands_scheduler_test.cpp",
        "//src/mongo/db/s/balancer:balancer_defragmentation_policy_test.cpp",
        "//src/mongo/db/s/balancer:balancer_policy_test.cpp",
        "//src/mongo/db/s/balancer:cluster_statistics_mock.h",
        "//src/mongo/db/s/balancer:migration_test_fixture.cpp",
        "//src/mongo/db/s/balancer:migration_test_fixture.h",
        "//src/mongo/db/s/balancer:move_unsharded_policy_test.cpp",
        "//src/mongo/db/s/config:configsvr_coordinator_service_test.cpp",
        "//src/mongo/db/s/config:index_on_config_test.cpp",
        "//src/mongo/db/s/config:initial_split_policy_test.cpp",
        "//src/mongo/db/s/config:set_cluster_parameter_coordinator_test.cpp",
        "//src/mongo/db/s/config:sharding_catalog_manager_add_shard_test.cpp",
        "//src/mongo/db/s/config:sharding_catalog_manager_add_shard_to_zone_test.cpp",
        "//src/mongo/db/s/config:sharding_catalog_manager_assign_key_range_to_zone_test.cpp",
        "//src/mongo/db/s/config:sharding_catalog_manager_bump_collection_version_and_change_metadata_test.cpp",
        "//src/mongo/db/s/config:sharding_catalog_manager_clear_jumbo_flag_test.cpp",
        "//src/mongo/db/s/config:sharding_catalog_manager_commit_chunk_migration_test.cpp",
        "//src/mongo/db/s/config:sharding_catalog_manager_config_initialization_test.cpp",
        "//src/mongo/db/s/config:sharding_catalog_manager_configure_collection_balancing_test.cpp",
        "//src/mongo/db/s/config:sharding_catalog_manager_ensure_chunk_version_is_greater_than_test.cpp",
        "//src/mongo/db/s/config:sharding_catalog_manager_merge_chunks_test.cpp",
        "//src/mongo/db/s/config:sharding_catalog_manager_remove_shard_from_zone_test.cpp",
        "//src/mongo/db/s/config:sharding_catalog_manager_remove_shard_test.cpp",
        "//src/mongo/db/s/config:sharding_catalog_manager_shard_collection_test.cpp",
        "//src/mongo/db/s/config:sharding_catalog_manager_split_chunk_test.cpp",
        "//src/mongo/db/s/resharding:resharding_coordinator_commit_monitor_test.cpp",
        "//src/mongo/db/s/resharding:resharding_coordinator_observer_test.cpp",
        "//src/mongo/db/s/resharding:resharding_coordinator_service_test.cpp",
        "//src/mongo/db/s/resharding:resharding_coordinator_test.cpp",
        "//src/mongo/db/s/resharding:resharding_service_test_helpers.h",
        "//src/mongo/db/s/resharding:resharding_util_test.cpp",
    ],
    tags = ["mongo_unittest_fourth_group"],
    deps = [
        ":config_server_test_fixture",
        ":sharding_commands_d",
        "//src/mongo/db:multitenancy",
        "//src/mongo/db:read_write_concern_defaults_mock",
        "//src/mongo/db/auth:authmocks",
        "//src/mongo/db/catalog:collection_mock",
        "//src/mongo/db/collection_crud",
        "//src/mongo/db/commands:cluster_server_parameter_commands_invocation",
        "//src/mongo/db/commands:set_feature_compatibility_version_idl",
        "//src/mongo/db/op_observer",
        "//src/mongo/db/pipeline:aggregation_context_fixture",
        "//src/mongo/db/pipeline:document_source_mock",
        "//src/mongo/db/repl:primary_only_service",
        "//src/mongo/db/repl:primary_only_service_test_fixture",
        "//src/mongo/db/repl:replication_info",
        "//src/mongo/db/repl:storage_interface_impl",
        "//src/mongo/db/repl:wait_for_majority_service",
        "//src/mongo/db/session:logical_session_cache_noop",
        "//src/mongo/db/session:session_catalog_mongod",
        "//src/mongo/db/timeseries:timeseries_options",
        "//src/mongo/db/transaction",
        "//src/mongo/db/transaction:transaction_api",
        "//src/mongo/executor:mock_async_rpc",
        "//src/mongo/idl:cluster_server_parameter_common",
        "//src/mongo/idl:server_parameter_test_util",
        "//src/mongo/util:version_impl",
    ],
)
